<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<%include('../../common/style.html'){}%>
<% var root = request.contextPath; %>
</head>
<body style="padding-top: 0;margin-top: 20px">
	<form id="search_form" role="form" class="form-inline" >
			<div class="form-group">
				<table class="table  table-condensed  table-bordered text-center">
					<tr>
						<td style="width: 90px;" class="active">用户名：</td>
						<td style="width: 120px;" class="formId">
							<input  type="text" id="p_username" name="p_username" 
							class="form-control input-sm text-height" placeholder="用户名" /> 
						</td>
						<td style="width: 90px;" class="active">邮箱：</td>	
						<td style="width: 120px;" class="formId">
							<input type="text"  name="p_email"  id="p_email" 
							class="input-sm form-control" placeholder="邮箱" /> 
						</td>	
					</tr>
<!-- 					<tr>
						<td style="width: 90px;" class="active">起始日期：</td>
						<td style="width: 120px;" class="formId">
							 <input id="p_start_ttime" name="p_start_ttime" class="form-control input-sm" placeholder="起始时间" readonly="readonly" style="cursor: pointer;"></input>
						</td>
						<td style="width: 90px;" class="active">终止日期：</td>
						<td style="width: 120px;" class="formId">
		                    <input id="p_end_time" name="p_end_time" class="form-control input-sm" placeholder="终止时间" readonly="readonly" style="cursor: pointer;"></input>
						</td>
					</tr> 
 -->				</table>
				<div class="form-group" >
					<button type="button"  id="searchButton"  onclick="doSearch()" class="btn btn-sm btn-primary">
						<i class="fa fa-search"></i>搜索
					</button>
					<button type="reset" class="btn btn-sm mls">重置</button>
					<#auth permissions="/sysUser/saveSysUser">
					<button type="button" style="margin-left: 10px;"  onclick="forInsert()" class="btn btn-sm btn-success">
						<i class="fa fa-plus"></i>新增
					</button>
					</#auth>
			</div>
			</div>
	</form>
	<div class="grid_wrapper"  style="">
		<table id="sysUser_data_table" class="table-condensed table-bordered table-striped table-hover" style="width: 100%">
			<tr>
				<th w_render="businessSerial" width="3%">序号</th> 
				<th w_index="username" width="7%" w_tip="true">用户名</th>
				<th w_index="email" width="7%" w_tip="true">邮 箱</th>
				<th w_index="age" width="4%" >年 龄</th>
				<th w_index="phone" width="7%">联系方式</th>
				<th w_render="sexRender" width="4%" >性 别</th>
				<th w_index="address" width="20%">地 址</th>
				<th w_render="roleName" width="4%">角 色</th>
				<th w_render="stateRender" width="4%">状 态</th>
				<th w_render="operateRender" width="8%">操 作</th>
			</tr>
		</table>
	</div> 
</body>
<script type="text/javascript">
var sysUser_data_table = null;
$(function(){
	sysUser_data_table = $.fn.bsgrid.init('sysUser_data_table', {
		url : '../sysUser/queryPage',
		pageSizeSelect: true,
		stripeRows: true,
		otherParames: $("#search_form").serializeArray(),
		pageSize : 10,
		additionalAfterRenderGrid: function(){
			$("[data-toggle='tooltip']").tooltip();
		}
	}); 
	 init_time_check();
});

/* 查询 */
function doSearch() {
	sysUser_data_table.options.otherParames =  $("#search_form").serializeArray();
	sysUser_data_table.gotoPage(1);
}

function init_time_check(){
	$("#starttime").datepicker({
		minView: "month",
		format: "yyyy-mm-dd", 
		language: 'zh-CN', 
		autoclose:true,
		todayHighlight: true
		}).on('changeDate', function(ev){
		    if($("#endtime").datepicker('getDate') && ev.date){
		    	if($("#endtime").datepicker('getDate').getTime()< ev.date.valueOf()){
		    		$("#starttime").datepicker('update','');
		    	}
		    }
		});
	$("#endtime").datepicker({
		minView: "month",
		format: "yyyy-mm-dd", 
		language: 'zh-CN', 
		autoclose:true,
		todayHighlight: true
		}).on('changeDate', function(ev){
		    if($("#starttime").datepicker('getDate') && ev.date){
		    	if($("#starttime").datepicker('getDate').getTime()> ev.date.valueOf()){
		    		$("#endtime").datepicker('update','');
		    	}
		    }
		});
}

function businessSerial(record, rowIndex, colIndex, options){
	return sysUser_data_table.options.settings.pageSize * (sysUser_data_table.options.curPage - 1) + rowIndex + 1;
}

function operateRender(record, rowIndex, colIndex, options){
	var html ='';
		html +='<#auth permissions="/sysUser/updateSysUser"><a class="btn btn-primary btn-xs mhx " style="color:#ffffff" href="javascript:void(0);" onclick="update(' + record.userId + ')">编辑</a></#auth>';
		html +='<#auth permissions="/sysUser/delSysUserById"><a class="btn btn-danger btn-xs mhx" style="color:#ffffff" href="javascript:void(0);" onclick="del(' + record.userId + ')">删除</a></#auth>';
	return html;
}

function sexRender(record, rowIndex, colIndex, options){
	var sex = record.sex;
    return sex==0?'女':'男';
}

function roleName(record, rowIndex, colIndex, options){
	var role = record.sysRole;
	return role.roleName;
}

function stateRender(record, rowIndex, colIndex, options){
	var state = record.state;
    return state==0?'停用':'启用';
}

function forInsert(){
	var forInsert = "../sysUser/forInsert";
	location.href = forInsert;
}

function update(userId){
	var forInsert = "../sysUser/forUpdate?userId="+userId;
	location.href = forInsert;
}

function del(userId){
	var d = dialog({
	    title: '提示',
	    okValue: '确定',
	    content: "确认删除该记录?",
	    width: 200,
	    cancelValue: '取消',
	    cancel: function () {},
	    ok: function () {
	    	$.ajax({
				type: "post",
				url: "../sysUser/delSysUserById",
				data:{userId:userId},
				success: function(data, textStatus){
					var d1 = dialog({
					    content: data.info
					});
					d1.show();
					setTimeout(function () {
					    d1.close().remove();
					}, 2000);
					doSearch();
				}
			});
	    }
	});
	d.show();
}
</script>
</html>